package com.share.notification.jconsole;

import java.lang.management.ManagementFactory;
import java.rmi.registry.LocateRegistry;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;

/**
 * MBean 接入层
 *
 */
public class NotifyHelloAgent {

	public static void main(String[] args)  throws Exception {
		MBeanServer server = ManagementFactory.getPlatformMBeanServer();
		ObjectName notifyHello = new ObjectName("sunxj-jmx:name=notifyHello");
		server.registerMBean(new NotifyHello(), notifyHello);
		
		System.out.println("NotifiHelloAgent start...");
		Thread.sleep(111110000000000000L);
		


//		try {
//			// 注册一个端口，绑定url后用于客户端通过rmi方式连接JMXConnectorServer
//			LocateRegistry.createRegistry(9999);
//			// URL路径
//			JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost:9999/jndi/rmi://localhost:9999/jmxDefault");
//			JMXConnectorServer jcs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
//			System.out.println("NotifiHelloAgent start...");
//			jcs.start();
//		} catch (Exception e) {
//			e.printStackTrace();
//		}

	}

}
